package org.iteye.bbjava.util.jdbc.concre;

import java.sql.DriverManager;
import java.sql.SQLException;

import org.iteye.bbjava.util.jdbc.AbstractJdbcConfig;
import org.iteye.bbjava.util.jdbc.JdbcConfig;
import org.iteye.bbjava.util.jdbc.conn.ConnectParam;

import com.mysql.jdbc.Connection;

public class JdbcConfigMySQL extends AbstractJdbcConfig implements JdbcConfig {

	ConnectParam param;
	
	@Override
	public ConnectParam getConfig() {
		ConnectParam param = new ConnectParam();
		param.setDataBaseName("blade");
		return param;
	}

	/***
	 * 获取连接对象
	 * 
	 * @return jdbc连接对象
	 * 
	 * */
	@Override
	public java.sql.Connection getConnection() {

		ConnectParam param = this.getConfig();
		param.setUrl("jdbc:mysql://localhost:3306/ads");
		param.setDriverName("com.mysql.jdbc.Driver");
		param.setName("root");
		param.setPassword("123456");
		java.sql.Connection conn = null;
		try {
			 Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = (Connection) DriverManager.getConnection(param.getUrl(),
					param.getName(), param.getPassword());
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}
	
	public static void main(String[] args) {
		java.sql.Connection conn = new JdbcConfigMySQL().getConnection();
		System.out.println(conn);
	}

	@Override
	public void setConnectParam(ConnectParam cp) {
			this.param = cp;		
	}

}
